//
//  HttpMessage.hpp
//  myhttpserver
//
//  Created by tgy on 2018/3/19.
//  Copyright © 2018年 tgy. All rights reserved.
//

#ifndef HttpMessage_hpp
#define HttpMessage_hpp

#include <stdio.h>
#include <map>
#include <string>

#define METHODCOUNT 9

static const char *const RequestMethod[METHODCOUNT] = {
    "HEAD", // 0
    "GET", // 1
    "POST", // 2
    "PUT", // 3
    "DELETE", // 4
    "TRACE", // 5
    "OPTIONS", // 6
    "CONNECT", // 7
    "PATCH" // 8
};

enum METHODENUM{

    HEAD, // 0
    GET, // 1
    POST, // 2
    PUT, // 3
    DELETE, // 4
    TRACE, // 5
    OPTIONS, // 6
    CONNECT, // 7
    PATCH // 8
};


enum STAUTS{
  
    // 1xx Informational
    CONTINUE = 100,
    
    // 2xx Success
    OK = 200,
    
    // 3xx Redirection
    
    // 4xx Client Error
    BAD_REQUEST = 400,
    NOT_FOUND = 404,
    
    // 5xx Server Error
    SERVER_ERROR = 500,
    NOT_IMPLEMENTED = 501
    
};

//主要是负责解析和设置请求和响应信息的
class HttpMessage {
    
private:
    std::string data;
    bool setMethod(const std::string method);
    void setHeadsFromVector(const std::vector<std::string> headKeyValue);
    
protected:
    std::map<std::string, std::string> heads;
    //服务器路径
    std::string path;
    std::string httpVersion;
    int method;
    //response 服务器的状态
    STAUTS stauts;
   
public:
    HttpMessage();
    HttpMessage(std::string data);
    virtual ~HttpMessage();
    //解析
    bool parse();
    int getMethod();
    std::string getPath();
    void addHeader(std::string key,std::string value);
    void setStauts(STAUTS stauts);
};

#endif /* HttpMessage_hpp */
